<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>functionstaff</title>
</head>

<body>
    <input type="text" class="input_func"><button>执行</button>
</body>
<script>
    // 立即执行函数
    (function() {
        console.log("我会立即执行");
    })();

    // 函数名作为参数 去执行
    var inputFunc = document.querySelector(".input_func");
    var btn = document.querySelector("button");
    var func1 = function() {
        console.log("func1");
    }
    var func2 = function() {
        console.log("func2");
    }
    var func3 = function() {
        console.log("func3");
    }
    btn.addEventListener("click", function(e) {
            var value = inputFunc.value;
            console.log(value);

        })
        // 做一个家族继承
    var fruit = function() {}
    fruit.prototype.eat = function() {
        console.log("吃");
    }

    var apple = function() {}
    apple.prototype = new fruit();
    apple.prototype.peel = function() {
        console.log("果皮是红色");
    }

    var banana = function() {}
    banana.prototype = new fruit();
    banana.prototype.peel = function() {
        console.log("果皮是黄色");
    }

    var watermelon = function() {}
    watermelon.prototype = new fruit();
    watermelon.prototype.peel = function() {
        console.log("果皮是绿色");
    }

    var apple = new apple();
    var banana = new banana();
    var watermelon = new watermelon();
    apple.eat();
    apple.peel();
    banana.eat();
    banana.peel();
    watermelon.eat();
    watermelon.peel();

    // 做一个对象合并的函数,做一个数组的合并的函数(for in)
    var extend = function() {
        var objs = arguments;
        var target = arguments[0];
        var i = 1;
        if (objs.length == 1) {
            target = jQuery;
            i--;
        }
        for (; i < objs.length; i++) {
            var obj = objs[i];
            for (pName in obj) {
                target[pName] = obj[pName];
            }
        }
        return target;
    }
    var a = {
        name: "翠花",
        score: 99,
        city: "广州"
    };
    var b = {
        name: "大翠花",
        score: 89,
        cook: "肘子"
    };
    var c = {
        name: "大大翠花",
        score: 79,
        song: "我是一只火鸟"
    };
    // var d = {
    //     interesting: {
    //         balla: "足球",
    //         ballb: "篮球",
    //         ballc: "保龄球",
    //     }
    // }
    // var e = {
    //     interesting: {
    //         balla: "足球",
    //         balld: "菜花",
    //         balle: "红花",
    //     }
    // }
    var CuiHua = extend({}, a, b, c);
    console.log(CuiHua);
    // var CuiHua1 = $.extend({}, d, e);
    // var CuiHua2 = $.extend(true, {}, d, e);
    // console.log(CuiHua1);
    // console.log(CuiHua2);

    // 传入任意数目的参数（类型数字），然后计算他们和（arguments）
    var add = function() {
        var a = 0;
        for (var i = 0; i < arguments.length; i++) {
            a = a + arguments[i];
        }
        return a;
    }
    console.log(add(12, 20, 11));
</script>

</html>